package study.springcloud.gateway.service.auth;

import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Service;
import org.springframework.web.server.ServerWebExchange;
import study.springcloud.gateway.support.utils.WebUtils;

@Slf4j
@Service("U2Token")
public class U2TokenAuthService implements AuthService {

    private static final String X_TOKEN = "X-Token";

    @Override
    public boolean doAuth(ServerWebExchange exchange, ServerHttpRequest request) {
        String token = WebUtils.getRequestHeader(exchange, X_TOKEN);
        if (StrUtil.isEmpty(token)) {
            log.warn("[Token Auth] fail: token empty");
            return false;
        }
        log.info("[Token Auth] token: {}");
        return true;
    }
}
